package com.oneonefive.trainticketsystem.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.oneonefive.trainticketsystem.mapper.RefundMapper;
import com.oneonefive.trainticketsystem.pojo.Refund;
import com.oneonefive.trainticketsystem.service.RefundService;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

@Service
public class RefundServiceImpl extends ServiceImpl<RefundMapper, Refund>
    implements RefundService {

    final
    RefundMapper refundMapper;

    public RefundServiceImpl(RefundMapper refundMapper) {
        this.refundMapper = refundMapper;
    }

    @Override
    public List<Refund> selectAllRef(Integer refundId, Integer ticketId,  Integer userId, Integer page) {
        return refundMapper.selectAllRefund( refundId,  ticketId, userId,(page-1)*10);
    }

    @Override
    public int getRefRowCount(Integer refundId, Integer ticketId, Integer userId) {
        return refundMapper.getRefRowCount( refundId,  ticketId, userId);
    }

    @Override
    public void insertOrUpdate(Integer refundId, Integer ticketId, String refundTime, Integer userId) {
        Timestamp t1 = null;
        System.out.println("refundTime"+refundTime);
        if (refundTime.length()==0) {
            Date date=new Date();
            t1=new Timestamp(date.getTime());
        }
        else t1=Timestamp.valueOf(refundTime.substring(0, 10) + " " + refundTime.substring(11, 19));
        refundMapper.insertRefund( refundId,  ticketId,  t1, userId);
    }
}




